
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author cloud
 */
public class DBmgr {
    
    public static float getProductInfo(String product) {
        float result = 0;
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection ("jdbc:mysql://localhost:3306/Prodotti", "root", "");
        stmt = con.createStatement();
        String qry = "SELECT Price FROM Prodotti WHERE Name='" + product +"'";
        System.out.println(qry);
        rs = stmt.executeQuery("SELECT Price FROM Prodotti WHERE Name='" + product +"'");
        
        while (rs.next()) 
        {
         result = rs.getFloat("Price"); 
         System.out.println(result);
        }
        rs.close();
        stmt.close();
        con.close();
        } catch (Exception e) { e.printStackTrace(); }
        System.out.println(result);
        return result;
        }
}
